"""
我的页面对象
"""
import allure
from selenium.webdriver.common.by import By
from base.base_page import BasePage, BaseProxy
from page.home_page import HomeProxy
from page.setting_page import SettingProxy


class MePage(BasePage):
    def __init__(self):
        super().__init__()
        self.username_register_btn = By.XPATH, '//*[@text="登录/注册"]'
        self.setting_btn = By.ID, 'com.bjcsxq.chat.carfriend:id/mine_set_rl'


    def find_username_register_btn(self):
        return self.get_element(self.username_register_btn)

    def find_setting_button(self):
        return self.get_element(self.setting_btn)




class MeHandler:
    def __init__(self):
        self.me_page = MePage()

    @allure.step(title='点击注册/登录按钮')
    def click_username_register_button(self):
        self.me_page.find_username_register_btn().click()

    @allure.step(title='点击设置按钮')
    def click_setting_button(self):
        self.me_page.find_setting_button().click()




class MeProxy(BaseProxy):
    def __init__(self):
        super().__init__()
        self.me_handler = MeHandler()

    @allure.step(title='流程:去登录页面')
    def go_login_page(self):
        """
        去登录页面
        """
        self.me_handler.click_username_register_button()

    @allure.step(title='流程:检查是否登录成功')
    def check_is_login_success(self):
        """
        检查是否登录成功
        :return:
        """
        if self.is_element_exist(self.me_handler.me_page.username_register_btn):
            # 能找到登录/注册说明没有登录成功
            return False
        else:
            # 找到了说明没有登录过
            return True

    @allure.step(title='流程:去设置页面')
    def go_setting_page(self):
        """
        去设置页面
        :return:
        """
        self.me_handler.click_setting_button()

if __name__ == '__main__':

    HomeProxy().go_me_page()
    me_page = MeProxy()
    print(me_page.check_is_login_success())
    if me_page.check_is_login_success():
        me_page.go_setting_page()
        SettingProxy().quit_login()
    else:
        me_page.go_login_page()